package com.zzb.zzb.controller;

import com.zzb.zzb.entity.User;
import com.zzb.zzb.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("user")
@Controller
public class UserController {
    @Autowired
    UserMapper userMapper;
   @RequestMapping("add")
   @ResponseBody
    public String add(){
       User user = new User();
       user.setName("张志斌");
       user.setAge(18);
       user.setId(1);
       userMapper.add(user);
       return "添加成功";
   }

    /**
     * 这是删除方法
     * @return
     */
   @RequestMapping("delete")
    @ResponseBody
    public String delete(){
       userMapper.delete(40);
       return "删除成功";
   }
   @RequestMapping("edit")
    @ResponseBody
   public String update(){
       User user=new User();
       user.setId(5);
       user.setName("张志斌");
       user.setAge(25);
       userMapper.update(user);
       return "修改成功";
   }
    @RequestMapping("list")
    @ResponseBody
    public List<User> list(){
        List<User> list = userMapper.list();
        return list;
    }

}
